<?php

namespace  Core;
class App
{
    private $config;
    private $kernel;
    private static $_instance;

    public function __construct($config)
    {
        $this->config = $config;
        $this->container = new Container();
    }

    public static function createInstance($config)
    {
        if(empty(self::$_instance)) {
            self::$_instance = new App($config['setting']);
        }
        return self::$_instance;
    }

    public function capture($kernel) {
       if($kernel instanceof  Kernel) {
           $this->kernel = $kernel;
        } else {
          throw new \Exception("无法加载内核");
       }
       return ;
    }

    public function run() {

        $request = $this->kernel->request();
        $response = $this->kernel->response();
        $process = $this->kernel->process();
        $respone = $process->run($request,$response);

        return $respone;
    }

}